﻿using System;
using FluentValidation;

namespace GiveAQuiz.Web.Helpers
{
  /// <summary>
  /// Extension methods for the FluentValidation framework.
  /// </summary>
  public static class FluentValidationExtensions
  {
    /// <summary>
    /// This extension method allows the FluentValidation framework to validate
    /// string properties for null or whitespace (vs. NotEmpty() which simply
    /// validates for null or empty - i.e. "" vs " ")
    /// </summary>
    /// <typeparam name="T">The Type being validated.</typeparam>
    /// <param name="ruleBuilder">The FluentValidation IRuleBuilder interface.</param>
    /// <returns>An IRuleBuilderOptions reference that includes a validation check 
    /// for the Property that states it must not be null nor contain only whitespace.</returns>
    public static IRuleBuilderOptions<T, string> NotBlank<T>(this IRuleBuilder<T, string> ruleBuilder)
    {
      return ruleBuilder.Must(val => !String.IsNullOrWhiteSpace(val));
    }    
  }
}